import chaosLib
import encImg as enc
import numpy as np
def decryptImage(cipher, prng):
    '''
    :param cipher: cipher
    :param prng: chaos based pseudorandom sequences
    :return: plain image
    '''

    img_confuse_B = cipher[:, :, 0]
    img_confuse_G = cipher[:, :, 1]
    img_confuse_R = cipher[:, :, 2]

    # 1. inverse confuse
    img_diff_B = enc.enc_confuse(img_confuse_B, -10)
    img_diff_G = enc.enc_confuse(img_confuse_G, -10)
    img_diff_R = enc.enc_confuse(img_confuse_R, -10)

    # 2. inverse diffusion process
    [l, h, w] = cipher.shape
    img = np.uint8(np.zeros([l, h, w]))
    img[:,:,0] = enc.enc_diffusion(img_diff_B, prng[0, :].reshape(l, h))
    img[:,:,1] = enc.enc_diffusion(img_diff_G, prng[1, :].reshape(l, h))
    img[:,:,2] = enc.enc_diffusion(img_diff_R, prng[0, :].reshape(l, h))

    return img

